<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
	<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
		<html>

		<head>
			<meta charset="utf-8" />
			<meta name="viewport" content="width=device-width, initial-scale=1.0" />

			<!--360浏览器优先以webkit内核解析-->

			<title>H+ 后台主题UI框架 - 主页示例</title>

			<link rel="shortcut icon" href="favicon.ico" />
			<link href="static/css/bootstrap.min.css?v=3.3.7" rel="stylesheet" />
			<link href="static/css/font-awesome.css?v=4.4.0" rel="stylesheet" />
			<link rel="stylesheet" href="static/js/plugins/layui/css/layui.css">
			<link href="static/css/animate.css" rel="stylesheet" />
			<link href="static/css/style.css?v=4.1.0" rel="stylesheet" />
		</head>
		<style>
			.m_right {
				margin-right: 30px;
			}
			.m_top{
				margin-top: 20px;
			}
		</style>

		<body class="gray-bg">

			<form >
			<div class="layui-form layuimini-form">
				<div class="layui-form-item">
					<label class="layui-form-label required">用户名</label>
					<div class="layui-input-block">
						<input type="text" name="username" lay-verify="required" lay-reqtext="用户名不能为空"
							placeholder="请输入用户名" value="" class="layui-input" id="username">
						<!-- <tip>填写自己管理账号的名称。</tip> -->
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label required">账号</label>
					<div class="layui-input-block">
						<input type="text" name="zhanghao" lay-verify="required" lay-reqtext="账号不能为空"
							placeholder="请输入账号" value="" class="layui-input" id="zhanghao">
						
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label required">密码</label>
					<div class="layui-input-block">
						<input type="password" name="password" lay-verify="required" lay-reqtext="密码不能为空"
							placeholder="请输入密码" value="" class="layui-input" id="password">
						
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label required">性别</label>
					<div class="layui-input-block">
						<input type="radio" name="sex" value="男" title="男" id="sex1">
						<input type="radio" name="sex" value="女" title="女" id="sex2">
					</div>

				</div>
				<div class="layui-inline">
					<label class="layui-form-label">权限</label>
					<div class="layui-input-inline">
						<select name="modules" lay-verify="required" lay-search="" id="modules">
							<option value="0">请选择权限</option>
							<option value="1">管理员</option>
							<option value="2">普通用户</option>

						</select><span id="add_hint3"></span>

					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn"type="submit" id="qr"
							>确认保存</button>
					</div>
				</div>
			</div>
			</form>
			<!-- 全局js -->
			<script src="static/js/jquery.min.js?v=2.1.4"></script>
			<script src="static/js/bootstrap.min.js?v=3.3.7"></script>
			<script src="static/js/plugins/layer/layer.min.js"></script>
			<script src="static/js/plugins/layui/layui.js"></script>

			<!-- 自定义js -->
			<script src="static/js/content.js"></script>

			<!-- 欢迎信息 -->
			<script src="static/js/welcome.js"></script>

			<script>


				$("#sex2").attr("checked", true);
				layui.use(['form'], function () {
					var form = layui.form,
						layer = layui.layer,
						$ = layui.$;

					//监听提交
					form.on('submit(saveBtn)', function (data) {
						let  sex;
						if (document.getElementById("sex1").checked == true) {
							sex=document.getElementById("sex1").value;
						} else if(document.getElementById("sex2").checked == true){
							sex=document.getElementById("sex2").value;
						}
						let  username=document.getElementById("username").value;
						let  zhanghao=document.getElementById("zhanghao").value;
						let  password=document.getElementById("password").value;
						let  qx=document.getElementById("modules").value;
						$.ajax({
							"url":'usercrud?opr=insert',
							"datatype":'int',
							"type":'post',
							"async": false,
							"data":({ "username": username,"zhanghao":zhanghao,"password":password,"sex":sex,"qx":qx}),
							"success": function (data) {
								if (data>0){
									var iframeIndex = parent.layer.getFrameIndex(window.name);
									parent.layer.close(iframeIndex);
								}
							}

						})


						let ss = document.getElementById("modules");
						let index1 = ss.selectedIndex;
						let tint3 = $("#add_hint3");
						if (index1 == 0) {
							tint3.html("必须选择一项！！！");
						}

						// var index = layer.alert(JSON.stringify(data.field), {
						// 	title: '最终的提交信息'
						// }, function () {
						//
						// 	关闭弹出层
						// 	layer.close(index);
						//

						//
						// });
						//
						return false;
					});

					$("#password").blur(function () {
						let password = $("#password").val();
						let tint2 = $("#add_hint2");
						if (password.length != 6) {
							tint2.html("请重新输入！密码是六位")
						}else{
							tint2.html("")
						}
					})
					$("")
				});
			</script>
		</body>

		</html>